﻿Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Configuration
Imports System.IO

<RunInstaller(True)> _
Public Class MyInstallerClass
    Inherits Installer

    Public Sub New()
        MyBase.New()

        AddHandler Me.Committed, AddressOf MyInstaller_Committed
        AddHandler Me.Committing, AddressOf MyInstaller_Committing
    End Sub 'New 

    Private Sub MyInstaller_AfterInstall(sender As Object, e As InstallEventArgs) Handles MyBase.AfterInstall
        Dim TargetDirectory As String = Path.GetDirectoryName(Context.Parameters("AssemblyPath"))

        Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(String.Format("{0}\SIPRO.exe", TargetDirectory))
        Dim dialog As New frmSQLConnectionDialog()
        dialog.ConnectionString = config.ConnectionStrings.ConnectionStrings("conn").ConnectionString
        dialog.RootPath = TargetDirectory + "\"

        If dialog.ShowDialog() = DialogResult.OK Then
            Dim CS As String = dialog.ConnectionString
            config.ConnectionStrings.ConnectionStrings("conn").ConnectionString = CS
            config.Save(ConfigurationSaveMode.Modified)
            ConfigurationManager.RefreshSection("connectionStrings")
        End If
    End Sub

    Private Sub MyInstaller_Committing(ByVal sender As Object, ByVal e As InstallEventArgs)
    End Sub

    Private Sub MyInstaller_Committed(ByVal sender As Object, ByVal e As InstallEventArgs)

    End Sub

    Public Overrides Sub Install(ByVal savedState As IDictionary)
        MyBase.Install(savedState)
    End Sub

    Public Overrides Sub Commit(ByVal savedState As IDictionary)
        MyBase.Commit(savedState)
    End Sub

    Public Overrides Sub Rollback(ByVal savedState As IDictionary)
        MyBase.Rollback(savedState)
    End Sub

    Public Shared Sub Main()

    End Sub
End Class
